package xyz.eden.cloud.common.web.spring;//package com.welink.paas.pms.common.spring;
//
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
//import org.springframework.core.env.PropertiesPropertySource;
//import org.springframework.core.env.PropertySource;
//import org.springframework.core.io.support.EncodedResource;
//import org.springframework.core.io.support.PropertySourceFactory;
//import org.springframework.lang.Nullable;
//
//import java.io.FileNotFoundException;
//import java.io.IOException;
//import java.util.Properties;
//
//@Slf4j
//public class YamlPropertySourceFactory implements PropertySourceFactory {
//    @Override
//    public PropertySource<?> createPropertySource(@Nullable String name, EncodedResource resource) throws IOException {
//
//        // 请配置注解参数：ignoreResourceNotFound = true
//        try {
//            String sourceName = name != null ? name : resource.getResource().getFilename();
//            //1.创建yaml文件解析工厂
//            YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
//            //2.设置资源内容
//            yaml.setResources(resource.getResource());
//            //3.解析成properties文件
//            Properties properties = yaml.getObject();
//            if (properties == null) {
//                throw new FileNotFoundException();
//            }
//            //4.返回符合spring的PropertySource对象
//            return new PropertiesPropertySource(sourceName, properties);
//        } catch (Exception e) {
//            throw new IOException("Yaml解析异常，异常原因：" + e.getMessage());
//        }
//    }
//}
